#include <iostream>
using namespace std;

typedef struct _list_node{
	int value;
	struct _list_node* next;
}list_node;

list_node* get_list(int* sz, int length) {
	list_node* pl = NULL;
	list_node* tl = NULL;

	for (int i=0; i<length; i++) {
		if (pl == NULL)	{
			pl = (list_node*)malloc(sizeof(list_node));
			pl->next = NULL;
			pl->value = sz[i];

			tl = pl;
		}
		else {
			list_node* node = (list_node*)malloc(sizeof(list_node));
			node->next = NULL;
			node->value = sz[i];
			tl->next = node;
			tl = node;
		}
	}

	return pl;
}

list_node* reverse_list(list_node* pl) {
	list_node* prev = NULL, *curr = NULL, *next = NULL, *rhead = NULL;

	curr = pl;
	next = pl->next;

	while (curr != NULL) {
		next = curr->next;
		if (next == NULL)
			rhead = curr;

		curr->next = prev;
		prev = curr;
		curr = next;
	}

	return rhead;
}

list_node* merge_list(list_node* l1, list_node* l2) {
	if (l1 ==  NULL)
		return l2;
	else if (l2 == NULL) 
		return l1;
	
	list_node* head = NULL;
	if (l1->value < l2->value) {
		head = l1;
		l1->next = merge_list(l1->next, l2);
	}
	else {
		head = l2;
		l2->next = merge_list(l1, l2->next);
	}

	return head;
}

//int main() {
//	int sz1[] = {1, 3, 5, 7, 9};
//	int sz2[] = {2, 4, 6, 8, 10};
//	list_node* p1 = get_list(sz1, 5);
//	list_node* p2 = get_list(sz2, 5);
//	//list_node* rpl = reverse_list(pl);
//	list_node* mpl = merge_list(p1, p2);
//
//	return 0;
//}